package com.wjh.www.dao.mapper;

import com.wjh.www.annotation.mybatis.ReturnType;
import com.wjh.www.annotation.mybatis.Select;
import com.wjh.www.annotation.spring.Component;
import com.wjh.www.entity.po.Role;
import com.wjh.www.proxy.constans.DataType;

import java.util.List;

/**
 * @author wjh
 * @date 2021/9/10 12:47
 * @Package com.wjh.anyview.dao.mapper
 */
@Component
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 查询用户的角色
     *
     * @param userId 用户id
     * @return 返回List<Role>
     */
    @Select(sql = "SELECT *\n" +
            "        FROM `role`\n" +
            "        WHERE id IN (\n" +
            "            SELECT role_id\n" +
            "            FROM `user_role`\n" +
            "            WHERE user_id = ?\n" +
            "        )")
    @ReturnType(returns = DataType.LIST)
    List<Role> listRoleByUserId(Long userId);
}
